// pages/i_detailxq/i_detailxq.js
const app = getApp()
var get_order_offer;var save_order_user;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    info:{},
    role_id:0,
    uid:'',
    aid:'',
    order_status:'',
    pay_status:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var id = options.id;
    var uid = options.uid;
    var order_status = options.order_status;
    var pay_status = options.pay_status;
    var aid = wx.getStorageSync('uid');
    var role_id = app.data.role_id;
    that.setData({
      role_id:role_id,
      uid:uid,
      aid:aid,
      order_status:order_status,
      pay_status:pay_status
    })
    get_order_offer = app.data.index_url + 'get_order_offer';
    save_order_user = app.data.ucenter_url + 'save_order_user';
    wx.request({
      url: get_order_offer,
      data: {
        id:id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log(res.data);
        var info = res.data.info;
        that.setData({
          info:info
        })
      }
    })
  },
  previewImgxc: function (e) {
    var that = this;
    var thumb = that.data.info.photos;
    var index = e.currentTarget.dataset.index;
    wx.previewImage({
      current: thumb[index],     //当前图片地址
      urls: thumb               //所有要预览的图片的地址集合 数组形式
    })
  },
  submit:function(e){
    var that = this;
    var info = that.data.info;
    var id = info.oid;
    var uid = info.uid;
    var price = info.price;
    var type = info.type;
    wx.showModal({
      title: '提示',
      content: '是否确认选择？',
      showCancel: true,
      success:function(e){
        if(e.confirm){
          wx.request({
            url: save_order_user,
            data: {
              id:id,
              uid:uid,
              price:price,
              type:type
            },
            header: {
              'content-type': 'application/json' // 默认值
            },
            success (res) {
              console.log(res.data);
              if(res.data.state == 1){
                wx.showModal({
                  title: '提示',
                  content: '操作成功！',
                  showCancel: false,
                  success:function(e){
                    wx.redirectTo({
                      url: '/pages/u_Rorder/u_Rorder',
                    })
                  }
                })
              }
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})